﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FairyGUI;
using Project.UI;
using DG.Tweening;
using XLua;

[LuaCallCSharp]
public class UIMainPageView : ViewController {

	public static string Package = "Project";
    public static string ResName = "UIMainPage";

    private GList _list;
   
    public override void ViewDidLoad(FairyGUI.Utils.XML xml)
    {
        base.ViewDidLoad(xml);
        Init();
    }

    void Init()
    {
       
        /*
        _list = GetChild("List").asList;
        _list.itemRenderer = RenderListItem;
        _list.itemProvider = ProviderListItem;
        _list.numItems = 5;
        _list.scrollPane.onScroll.Add(DoSpecialEffect);
        DoSpecialEffect();
        
        */ 
	}

    void DoSpecialEffect()
    {
        //change the scale according to the distance to middle
        float midX = _list.scrollPane.posX + _list.viewWidth / 2;
        int cnt = _list.numChildren;
        for (int i = 0; i < cnt; i++)
        {
            GObject obj = _list.GetChildAt(i);
            float dist = Mathf.Abs(midX - obj.x - obj.width / 2);
            UIItemPageView view = (UIItemPageView)obj.asCom;
            if (dist > obj.width) //no intersection
            {
                //obj.SetScale(1, 1);
                //view.SetSmallSize();
            }
            
            else
            {
                float ss = 1 + (1 - dist / obj.width) * 0.24f;
                //obj.SetScale(ss, ss);
                //view.SetBigSize();
            }
        }
    }


    void RenderListItem(int index, GObject obj)
    {
        if (obj.GetType() == typeof(UIItemPageView))
        {
            UIItemPageView listItem = (UIItemPageView)obj;
            listItem.SetData();

        }
    }

    string ProviderListItem(int index)
    {
        return UIPackage.GetItemURL("Project", "Item");
        
    }
   


}
